﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DslCrossModelFramework;
using DslCrossModelFramework.Environment;
using Xunit;

namespace UnitTest.xUnitTests.CrossModelFramework {

    /// <summary>
    /// Test class for the <see cref="EnvironmentConfiguration"/> class
    /// </summary>
    public class EnvironmentConfigurationTests {

        /// <summary>
        /// Tests that the environment configuration is detected after being registered
        /// </summary>
        [Fact]
        public void EnvironmentConfigurationExistsTest() {
            TestHelper.RegisterEnvironmentConfiguration();
            Assert.True(EnvironmentConfiguration.EnvironmentAvailable);
            Assert.NotNull(EnvironmentConfiguration.Current);
            Assert.IsType<Mocks.UnitTestEnvironmentConfiguration>(EnvironmentConfiguration.Current);
        }

        /// <summary>
        /// Tests that the correct number of model files are detected
        /// </summary>
        [Fact]
        public void EnvironmentConfigurationModelFiles() {
            TestHelper.RegisterEnvironmentConfiguration();
            Assert.Equal(3, EnvironmentConfiguration.Current.ModelFiles.Count);
        }

        /// <summary>
        /// Tests that the model directory is empty when no models have been loaded
        /// </summary>
        [Fact]
        public void EnvironmentConfigurationEmptyModelDirectory() {
            TestHelper.RegisterEnvironmentConfiguration();
            IModelDirectory directory = EnvironmentConfiguration.Current.GetModelDirectory();
            Assert.Equal(0, directory.AllElements().Count);
        }

        /// <summary>
        /// Tests that the model directory is not empty when the model files have been preloaded
        /// </summary>
        [Fact]
        public void EnvironmentConfigurationPreLoadModelFiles() {
            TestHelper.RegisterEnvironmentConfiguration();
            EnvironmentConfiguration.Current.GetModelDirectory().PreloadAllModelFiles();
            IModelDirectory directory = EnvironmentConfiguration.Current.GetModelDirectory();
            Assert.NotEqual(0, directory.AllElements().Count);
        }
    }
}
